]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Explicitly convert raw data to strings
authorFlorian Müllner <fmuellner@gnome.org>
Mon, 30 Jul 2018 12:35:27 +0000 (14:35 +0200)
committerFlorian Müllner <florian.muellner@gmail.com>
Tue, 31 Jul 2018 16:28:53 +0000 (16:28 +0000)
As strings are guaranteed to use UTF-8 in the GNOME platform, generic
file APIs like g_file_load_contents() return raw data instead. Since
gjs' recent update to mozjs60, this data is now returns as Uint8Array
which cannot simply be treated as string - its toString() method boils
down to arr.join(',') - so use gjs' new ByteArray module to explicitly
convert the data.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/179

js/misc/extensionUtils.js
js/ui/keyboard.js
js/ui/padOsd.js
js/ui/sessionMode.js

index 9f77b4c40746b8ba47adee7af8f9e3c177641ce8..6e39f87d7914e9af31423efc00d52640fd9eaade 100644 (file)
@@ -112,6 +112,8 @@ function createExtensionObject(uuid, dir, type) {
     let metadataContents, success, tag;
     try {
         [success, metadataContents, tag] = metadataFile.load_contents(null);
+        if (metadataContents instanceof Uint8Array)
+            metadataContents = imports.byteArray.toString(metadataContents);
     } catch (e) {
         throw new Error('Failed to load metadata.json: ' + e);
     }
index 1fefb8c6ca91cf18ea76caf2eaf9e44cd0fc58ce..1666a507b86e99d52dac0c9d30ded41a871a075e 100644 (file)
@@ -472,6 +472,8 @@ var KeyboardModel = new Lang.Class({
     _loadModel(groupName) {
         let file = Gio.File.new_for_uri('resource:///org/gnome/shell/osk-layouts/%s.json'.format(groupName));
         let [success, contents] = file.load_contents(null);
+        if (contents instanceof Uint8Array)
+            contents = imports.byteArray.toString(contents);
 
         return JSON.parse(contents);
     },
index 9b5986985e77d6e170589e606b7922bea21bebcd..8ef20b67bce625b395ade73ab2798c1236d04571 100644 (file)
@@ -313,6 +313,8 @@ var PadDiagram = new Lang.Class({
     _init(params) {
         let file = Gio.File.new_for_uri('resource:///org/gnome/shell/theme/pad-osd.css');
         let [success, css, etag] = file.load_contents(null);
+        if (css instanceof Uint8Array)
+            css = imports.byteArray.toString(css);
         this._curEdited = null;
         this._prevEdited = null;
         this._css = css;
index aac29ae5eee28c41a1a01f4d6c6b2721ab158c99..e22176415418f8fa31c21fb54d998c86bf00d85d 100644 (file)
@@ -117,6 +117,8 @@ function _loadMode(file, info) {
     let fileContent, success, tag, newMode;
     try {
         [success, fileContent, tag] = file.load_contents(null);
+        if (fileContent instanceof Uint8Array)
+            fileContent = imports.byteArray.toString(fileContent);
         newMode = JSON.parse(fileContent);
     } catch(e) {
         return;